// app/controller/home.js
const Controller = require('../core/base_controller');

class HouseController extends Controller {
  async getHouse() {
    let {type} = this.ctx.params
    const {pageindex=1,pagesize=10} = this.ctx.query;
    console.log(type,pageindex,pagesize);
    const results = await this.app.mysql.select('t_house', { // 搜索 t_house 表
      where: { tid: type=='all'?[1,2,3]:type,}, // WHERE 条件
    });
    this.ctx.body = {
      meta:{
        msg:"获取成功",
        status:200,
      },
      data:{
        list:results.slice((pageindex-1)*pagesize,pageindex*pagesize),
        total:results.length,
        size:pagesize
      }
    };
  }
  
}

module.exports = HouseController;

// aa.forEach(item=>{
    //   this.app.mysql.insert('t_house',item)
    // })
    // const result = await this.app.mysql.insert('t_house', { 
    //   "house_title": "中骏世界城",
    //   "house_tags": "环线房,绿化率高,大型社区,新盘首开",
    //   "city": "上海市",
    //   "tid": "3",
    //   "acreage": "96-106㎡",
    //   "url": "https://ke-image.ljcdn.com/newhouse-user-image/2c169da7f9ccbd54ca2f84546dea2832.jpg",
    //   "total_price": "225-315万/套",
    //   "per_price": "26000元/平",
    //   "longitude": "121.112491",
    //   "latitude": "31.304415",
    //   "house_type": "非毛坯",
    //   "address": "上海周边昆山光明路739号",
    //   "bedroom_count": "4室1厅"
    // });
    // console.log(result);